package com.wyp168.leetcode.entity;

import org.apache.tomcat.util.buf.Ascii;

/**
 * @ClassName Test
 * @Title TODO
 * @Description TODO
 * @Author wyp168
 * @Date 2022/10/10 19:38
 */
public class Test {
    public static void main(String[] args) {
        Test test = new Test();
        String s = "hello world";
        System.out.println(test.toUpCase(s));
    }

    public String toLowCase(String s) {
        int length = s.length();
        if (length == 0) {
            return s;
        }
        char[] chars = s.toCharArray();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            if (chars[i] >= 'A' && chars[i] <= 'Z') {
                int temp = chars[i] + 32;
                sb.append((char)temp);
                continue;
            }
            sb.append(chars[i]);
        }
        return sb.toString();
    }

    public String toUpCase(String s) {
        int length = s.length();
        if (length == 0) {
            return s;
        }
        char[] chars = s.toCharArray();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            if (chars[i] >= 'a' && chars[i] <= 'z') {
                int temp = chars[i] - 32;
                sb.append((char)temp);
                continue;
            }
            sb.append(chars[i]);
        }
        return sb.toString();
    }
}
